<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Create a phar-file format specific stub</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="phar.count.html">« Phar::count</a></li>
      <li style="float: right;"><a href="phar.decompress.html">Phar::decompress »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.phar.html">Phar</a></li>
    <li>Create a phar-file format specific stub</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="phar.createdefaultstub" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Phar::createDefaultStub</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL phar &gt;= 2.0.0)</p><p class="refpurpose"><span class="refname">Phar::createDefaultStub</span> &mdash; <span class="dc-title">Create a phar-file format specific stub</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-phar.createdefaultstub-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><strong>Phar::createDefaultStub</strong></span>(<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$index</code><span class="initializer"> = <strong><code>null</code></strong></span></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$webIndex</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type">string</span></div>


  <p class="para rdfs-comment">
   This method is intended for creation of phar-file format-specific stubs, and is
   not intended for use with tar- or zip-based phar archives.
  </p>
  <p class="para">
   Phar archives contain a bootstrap loader, or <code class="literal">stub</code>
   written in PHP that is executed when the archive is executed in PHP either via
   include:
   <div class="example-contents">
    <div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">include&nbsp;</span><span style="color: #DD0000">'myphar.phar'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   or by simple execution:
   <div class="example-contents screen">
    <div class="cdata"><pre>
php myphar.phar
    </pre></div>
   </div>
  </p>
  <p class="para">
   This method provides a simple and easy method to create a stub that will
   run a startup file from the phar archive.  In addition, different files can
   be specified for running the phar archive from the command line versus through
   a web server.  The loader stub also calls <span class="function"><a href="phar.interceptfilefuncs.html" class="function">Phar::interceptFileFuncs()</a></span>
   to allow easy bundling of a PHP application that accesses the file system.  If the
   phar extension is not present, the loader stub will extract the phar archive
   to a temporary directory and then operate on the files.  A shutdown function
   erases the temporary files on exit.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-phar.createdefaultstub-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">index</code></dt>

     <dd>

      <p class="para">
       Relative path within the phar archive to run if accessed on the command-line
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">webIndex</code></dt>

     <dd>

      <p class="para">
       Relative path within the phar archive to run if accessed through a web browser
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-phar.createdefaultstub-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a string containing the contents of a customized bootstrap loader (stub)
   that allows the created Phar archive to work with or without the Phar extension
   enabled.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-phar.createdefaultstub-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   Throws <span class="classname"><a href="class.unexpectedvalueexception.html" class="classname">UnexpectedValueException</a></span> if either parameter is longer
   than 400 bytes.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-phar.createdefaultstub-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">index</code> and <code class="parameter">webIndex</code> are now nullable.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-phar.createdefaultstub-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-730">
    <p><strong>示例 #1 A <span class="function"><strong>Phar::createDefaultStub()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$phar&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Phar</span><span style="color: #007700">(</span><span style="color: #DD0000">'myphar.phar'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$phar</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setStub</span><span style="color: #007700">(</span><span style="color: #0000BB">$phar</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">createDefaultStub</span><span style="color: #007700">(</span><span style="color: #DD0000">'cli.php'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'web/index.php'</span><span style="color: #007700">));<br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">Exception&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;handle&nbsp;errors<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-phar.createdefaultstub-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="phar.setstub.html" class="function" rel="rdfs-seeAlso">Phar::setStub()</a> - Used to set the PHP loader or bootstrap stub of a Phar archive</span></li>
    <li class="member"><span class="function"><a href="phar.getstub.html" class="function" rel="rdfs-seeAlso">Phar::getStub()</a> - Return the PHP loader or bootstrap stub of a Phar archive</span></li>
   </ul>
  </p>
 </div>



</div></div></div></body></html>